import request from '../utils/request'
const getUserChannelAPI = () => {
  return request({
    url: '/v1_0/user/channels'
  })
}

const getArticlesListAPI = ({ id, timestamp = Date.now() + '' }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: id,
      timestamp
    }
  })
}
const articleDislikeAPI = (id) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
const articleReportsAPI = ({ id, type, remark }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type,
      remark: type === '0' ? remark : remark || null
    }
  })
}
const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
const updateChannel = ({ channels }) => {
  return request({
    method: 'PUT',
    url: '/v1_0/user/channels',
    data: {
      channels
    }
  })
}
const GetSuggestion = (q) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q
    }
  })
}
// 搜索结果
const SearchList = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q,
      page
    }
  })
}
// 数据渲染
const articleDetailAPI = (id) => {
  return request({
    url: '/v1_0/articles/' + id
  })
}
// 关注
const followedUserAPI = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}
// 取消关注
const unFollowedUserAPI = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}
// 喜欢
const LikingsAPI = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target
    }
  })
}
// 不喜欢
const NolikingsAPI = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/likings/' + id
  })
}
// 获取用户评论
const CommentsAPI = ({ source, offset, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit
    }
  })
}
// 点赞
const HongLikingsAPI = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target
    }
  })
}
// 取消点赞
const NonLikingsAPI = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + id
  })
}
// 发布
const ComMentsAPI = ({ target, content }) => {
  return request({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target,
      content
    }
  })
}
export {
  getUserChannelAPI,
  getArticlesListAPI,
  articleDislikeAPI,
  articleReportsAPI,
  allChannelListAPI,
  updateChannel,
  GetSuggestion,
  SearchList,
  articleDetailAPI,
  followedUserAPI,
  unFollowedUserAPI,
  LikingsAPI,
  NolikingsAPI,
  CommentsAPI,
  HongLikingsAPI,
  NonLikingsAPI,
  ComMentsAPI
}
